package cn.iocoder.yudao.module.book.controller.app.records;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.book.controller.app.records.vo.AppRecordsRespVO;
import cn.iocoder.yudao.module.book.controller.app.user.vo.UserReadingStatsRespVO;
import cn.iocoder.yudao.module.book.service.records.RecordsService;
import cn.iocoder.yudao.module.book.service.user.UserStatsService;
import cn.iocoder.yudao.module.book.service.users.userDTOService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 阅读记录")
@RestController
@RequestMapping("/api/user/book")
//测试完成
public class AppBookRecordController {

    @Resource
    private userDTOService userService;

    @Resource
    private RecordsService recordsService;

    @Resource
    private UserStatsService userStatsService;

//    @GetMapping("/readSummary")
//    @Operation(summary = "获取阅读记录")
//    public CommonResult<List<AppRecordsRespVO>> readSummary(){
////        System.out.println(UserContext.getUserId());
//        return CommonResult.success(recordsService.getReadSummary(userService.getCurrentUserId()));
//    }


    @GetMapping("/readSummary")
    @Operation(summary = "获取用户阅读统计")
    public CommonResult<UserReadingStatsRespVO> getUserReadingStats() {
        Long userId = userService.getCurrentUserId();
        UserReadingStatsRespVO result = userStatsService.getUserReadingStats(userId);
        return success(result);
    }

    @GetMapping("/cleanHistory")
    @Operation(summary = "清空阅读记录")
    public CommonResult<Boolean> cleanHistory(){
        return CommonResult.success(recordsService.deleteByUserId(userService.getCurrentUserId()));
    }

    @GetMapping("/recentReadList")
    @Operation(summary = "最近阅读")
    public CommonResult<List<AppRecordsRespVO>> recentReadList(){
        return CommonResult.success(recordsService.getRecentWeekRecords(userService.getCurrentUserId()));
    }
}
